package com.itheima.controller;

import com.itheima.domain.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UserDemo {
    //获取Bean对象的三种方式
    @Test
    public void test1(){
            //强转
            ApplicationContext ac=new ClassPathXmlApplicationContext("spring.xml");
        User user = (User) ac.getBean("user");
        user.paly();

        System.out.println(user);
    }

    @Test
    public void test2(){
        ApplicationContext ac=new ClassPathXmlApplicationContext("spring.xml");
        User bean = ac.getBean(User.class);
        bean.paly();
        System.out.println(bean);
    }


    @Test
    public void test3(){
        ApplicationContext ac=new ClassPathXmlApplicationContext("spring.xml");
        User user = ac.getBean("user", User.class);
        user.paly();

        System.out.println(user);
    }
}
